package com.xhapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhapi.mapper.ErrorQuestionMapper;
import com.xhapi.pojo.dto.ScoreAvgBySubject;
import com.xhapi.pojo.dto.StudentOnePaperDTO;
import com.xhapi.pojo.entity.ErrorQuestion;
import com.xhapi.pojo.entity.Score;
import com.xhapi.service.IErrorQuestionService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 错题信息表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-05-02
 */
@Service
@RequiredArgsConstructor
public class ErrorQuestionServiceImpl extends ServiceImpl<ErrorQuestionMapper, ErrorQuestion> implements IErrorQuestionService {
    private final ErrorQuestionMapper errorQuestionMapper;
    @Override
    public String getErrorPaper(StudentOnePaperDTO studentOnePaperDTO) {
        Integer studentId = studentOnePaperDTO.getStudentId();
        String subject = studentOnePaperDTO.getSubject();
        Integer examCode = studentOnePaperDTO.getExamCode();
        QueryWrapper<ErrorQuestion> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("subject",subject).eq("student_id",studentId).eq("examCode",examCode);

        return errorQuestionMapper.selectList(queryWrapper).toString();
    }

    @Override
    public String arrange(List<Score> score, List<ScoreAvgBySubject> allMsg) {
        Map<String,Integer> oneMap=new HashMap<>();
        score.stream().forEach(s->{
            oneMap.put(s.getSubject(),s.getEtScore());
        });
        Map<String,Double> allMap=new HashMap<>();
        allMsg.stream().forEach(s->{
            if(oneMap.containsKey(s.getSubject()))
                allMap.put(s.getSubject(),s.getAvg());
        });

        return "我的成绩是"+oneMap.toString()+",整体成绩为"+allMap.toString();
    }
}
